package info.techgeek.labs.patterns.strategy.Duck2;
import java.util.Arrays;

public class TestDrive {

	public static void main(String[] arg) {

		// we program to interfaces, not to classes

		DuckSortable d1 = new Duck ("Mupsy", 4350, 145);
		DuckSortable d2 = new Duck ("Yaska", 464, 2344);
		DuckSortable d3 = new Duck ("Alexie", 541, 1405);
		DuckSortable d4 = new Duck ("Gismo", 4586, 55);
		DuckSortable[] ducks = { d1, d2, d3, d4 };

		System.out.println("--- Original list of ducks:");
		display(ducks);

		Arrays.sort(ducks);
		System.out.println();
		System.out.println("--- List of ducks, sorted by default:");
		display(ducks);

		// here we change SortStrategy
		for (int i = 0; i < ducks.length; i++) {
			ducks[i].setSortStrategy (new SortByName());
		}
        	Arrays.sort(ducks);
        	System.out.println();
		System.out.println("--- List of ducks sorted by name:");
        	display(ducks);

		// here we change SortStrategy
		for (int i = 0; i < ducks.length; i++) {
			ducks[i].setSortStrategy (new SortBySize());
		}
        	Arrays.sort(ducks);
        	System.out.println();
		System.out.println("--- List of ducks sorted by size:");
        	display(ducks);

		// here we change SortStrategy
		for (int i = 0; i < ducks.length; i++) {
			ducks[i].setSortStrategy (new SortByWeight());
		}
        	Arrays.sort(ducks);
        	System.out.println();
		System.out.println("--- List of ducks sorted by weight:");
        	display(ducks);

	}

	public static void display(DuckSortable[] ducks) {
		for (int i = 0; i < ducks.length; i++) {
			System.out.println(ducks[i]);
		}
	}

}